const express = require('express')
const cors = require('cors')
const session=require('express-session')
const bodyParse = require('body-parser')
const router = require('./routers/router')
const app = express()
const sequelize = require('./db.js')
app.use(bodyParse.urlencoded({extended:false}))
app.use(express.static('static'))
const cookieParser = require('cookie-parser')

app.use(cookieParser())

app.use((req,res,next)=>{
  req.db=sequelize
  next()
})

// session
app.use(session({
  secret: 'keyboard cat',
  resave: false,
  saveUninitialized: true,
}))


// 允许跨域请求
app.use(cors({
  credentials: true,
  origin: 'http://localhost:8080', // web前端服务器地址
}))



// 加载路由
app.use(router)

app.listen(8888,()=>{
  console.log('http://101.132.158.158:8888')
})